<template>
    <div class="wrap">
        <!--  头部  -->
        <list @loadmore="loadmore" loadmoreoffset="1" ref="list" :showRefresh="true" @refresh="onrefresh">
          <cell class="cell" v-for="i in lists.length/2">
            <ShopCell class="shopcell" v-bind:lbean="lists[2*i-2]" v-bind:rbean="lists[2*i-1]" v-if="lists[2*i-1] "></ShopCell>
            <ShopCell class="shopcell" v-bind:lbean="lists[2*i-2]" v-bind:rbean="empty" v-else></ShopCell>
          </cell>
        </list>
    </div>
</template>
<script>
    import ShopCell from '../component/shopcell';
    var globalEvent = weex.requireModule('globalEvent');
    var modal = weex.requireModule("bmModal");
    module.exports = {
        data() {
          return {
            page: 1,
            empty:{},
            lists: []
          }
        },
        components: {
          ShopCell
        },
        methods: {
            onrefresh() {
              this.page = 1;
              this.loadData();
            },
            loadData() {
              this.$notice.loading.show("请等待");
              this.$fetch({
                method: 'GET',
                url: 'https://888.ph100.cn/goodsList',
                data: {
                  cateid:'',
                  page:this.page,
                  pagesize:10
                }
              }).then(resData => {
                // 成功回调
                console.log(resData);
                this.$notice.loading.hide();
                this.$refs["list"].refreshEnd();
                if (this.page == 1) {
                  this.lists = [];
                }
                this.lists = this.lists.concat(resData["goodslist"]);
              }, error => {
                // 错误回调
                console.log(error);
                this.$notice.loading.hide();
                this.$refs["list"].refreshEnd();
              });
            },
            loadmore(event) {
              modal.toast({ message: 'loadmore'});
              this.page = this.page+1;
              this.loadData();
            }
        },
        created: function() {
          this.loadData();
          this.$event.on('ongoodclick', params => {
            this.$notice.loading.show("请等待");
            
          })
        }
    }
</script>
<style scoped>
.shopcell{
  width: 750px;
  height: 500px;
}
.cell{
  flex-direction: column;
  width: 750px;
  height: 500px;
}
</style>
